﻿package com.amcharts
{
    import com.amcharts.chartClasses.*;
    import com.amcharts.events.*;
    import com.amcharts.geom.*;
    import com.amcharts.layout.*;
    import com.amcharts.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import mx.collections.*;
    import mx.core.*;
    import mx.formatters.*;
    import mx.styles.*;

    public class AmLegend extends UIComponent
    {
        protected var _livePreviewRect:Sprite;
        protected var _dataProvider:ArrayCollection;
        protected var _legendCreated:Boolean;
        protected var _grid:Grid;
        protected var _negativeValueColor:Number;
        protected var _switchable:Boolean;
        protected var _initialTextColor:Number;
        protected var _switchType:String;
        protected var _filters:Array;
        protected var _counter:Number = 0;
        protected var _valueText:String = "[[value]]";
        protected var _switches:Array;
        protected var _numberFormatter:NumberFormatter;
        protected var _textClickEnabled:Boolean = true;
        protected var _useMarkerColorForLabels:Boolean;
        protected var _marginTop:Number;
        protected var _labelText:String = "[[title]]";
        protected var _valueFields:Array;
        protected var _background:Rect;
        protected var _marginRight:Number;
        protected var _adjustWidth:Boolean;
        protected var _marginBottom:Number;
        protected var _chart:AmChart;
        protected var _switchV:Class;
        protected var _entryContainers:Array;
        protected var _positiveValueColor:Number;
        protected var _percentFormatter:NumberFormatter;
        protected var _switchX:Class;
        protected var _usePositiveNegativeOnPercentsOnly:Boolean;
        protected var _valueFunction:Function;
        protected var _titleFields:Array;
        protected var _marginLeft:Number;
        private static var stylesInited:Boolean = initStyles();
        static const VERSION:String = "1.8.3.1";
        static const DEFAULT_MEASURED_WIDTH:Number = 500;

        public function AmLegend()
        {
            _switchX = AmLegend__switchX;
            _switchV = AmLegend__switchV;
            _valueFields = new Array();
            _titleFields = new Array();
            _switches = new Array();
            _entryContainers = new Array();
            _numberFormatter = new NumberFormatter();
            _numberFormatter.rounding = NumberBaseRoundType.NEAREST;
            _percentFormatter = new NumberFormatter();
            _percentFormatter.rounding = NumberBaseRoundType.NEAREST;
            _percentFormatter.precision = 1;
            return;
        }// end function

        public function get percentFormatter() : NumberFormatter
        {
            return _percentFormatter;
        }// end function

        override protected function updateDisplayList(param1:Number, param2:Number) : void
        {
            var _loc_3:String = null;
            super.updateDisplayList(param1, param2);
            if (UIComponentGlobals.designMode)
            {
                this.setStyle("backgroundColor", 13421772);
                this.setStyle("backgroundAlpha", 0.5);
            }
            else if (_dataProvider)
            {
                if (!_textClickEnabled)
                {
                }
                if (this.getStyle("rollOverGraphAlpha") == 1)
                {
                    this.setStyle("rollOverColor", this.getStyle("color"));
                }
                if (!_legendCreated)
                {
                    _grid.removeAllChildren();
                    if (_dataProvider.length > 0)
                    {
                        createLegend();
                    }
                    else
                    {
                        return;
                    }
                }
                _grid.x = _marginLeft;
                _grid.y = _marginTop;
                _grid.width = this.width - _marginLeft - _marginRight;
                _grid.maxColumns = getStyle("maxColumns");
                _grid.validateNow();
                _loc_3 = getStyle("align");
                if (_loc_3 == "center")
                {
                    _grid.x = _marginLeft + (_grid.width - _grid.realWidth) / 2;
                    _grid.validateNow();
                }
                if (_loc_3 == "right")
                {
                    _grid.x = this.width - _grid.realWidth - _marginRight;
                    _grid.validateNow();
                }
            }
            if (_background)
            {
                if (_background.parent == this)
                {
                    this.removeChild(_background);
                }
            }
            if (this.width)
            {
            }
            if (this.height)
            {
                _background = new Rect(this.width, this.height, [this.getStyle("backgroundColor")], [this.getStyle("backgroundAlpha")], 0, this.getStyle("borderColor"), this.getStyle("borderAlpha"));
                this.addChildAt(_background, 0);
            }
            return;
        }// end function

        protected function stylesChangedHandler(event:Event) : void
        {
            invalidateDisplayList();
            return;
        }// end function

        public function get numberFormatter() : NumberFormatter
        {
            return _numberFormatter;
        }// end function

        public function set useMarkerColorForLabels(param1:Boolean) : void
        {
            _useMarkerColorForLabels = param1;
            return;
        }// end function

        public function get useMarkerColorForLabels() : Boolean
        {
            return _useMarkerColorForLabels;
        }// end function

        public function get adjustWidth() : Boolean
        {
            return _adjustWidth;
        }// end function

        public function set numberFormatter(param1:NumberFormatter) : void
        {
            _numberFormatter = param1;
            return;
        }// end function

        protected function cleanFromEmpty(param1:String) : String
        {
            var _loc_2:* = param1.replace(/\[\[[^\]]*\]\]""\[\[[^\]]*\]\]/, "");
            return _loc_2;
        }// end function

        protected function dataChangedHandler(event:Event = null) : void
        {
            _legendCreated = false;
            _dataProvider = _chart.legendDataProvider;
            invalidateProperties();
            return;
        }// end function

        public function set percentFormatter(param1:NumberFormatter) : void
        {
            _percentFormatter = param1;
            return;
        }// end function

        override protected function createChildren() : void
        {
            super.createChildren();
            _grid = new Grid();
            this.addChild(_grid);
            if (UIComponentGlobals.designMode)
            {
                invalidateDisplayList();
            }
            return;
        }// end function

        public function rollOverItem(param1:uint) : void
        {
            var _loc_2:TextFormat = null;
            var _loc_3:Number = NaN;
            if (_titleFields[param1])
            {
                if (_titleFields[param1].enabled)
                {
                    _loc_2 = _titleFields[param1].defaultTextFormat;
                    _loc_3 = this.getStyle("rollOverColor");
                    if (_useMarkerColorForLabels)
                    {
                        _loc_2.color = _dataProvider.getItemAt(param1).legendKeyColor;
                    }
                    else
                    {
                        _loc_2.color = this.getStyle("rollOverColor");
                    }
                    _titleFields[param1].setTextFormat(_loc_2);
                }
            }
            return;
        }// end function

        protected function createLegend() : void
        {
            var _loc_5:Number = NaN;
            var _loc_17:Object = null;
            var _loc_18:ExtendedSprite = null;
            var _loc_19:String = null;
            var _loc_20:Number = NaN;
            var _loc_21:Number = NaN;
            var _loc_22:Number = NaN;
            var _loc_23:Sprite = null;
            var _loc_24:Sprite = null;
            var _loc_25:Sprite = null;
            var _loc_26:Number = NaN;
            var _loc_27:Number = NaN;
            var _loc_28:String = null;
            var _loc_29:Number = NaN;
            var _loc_30:Wedge = null;
            var _loc_31:IUITextField = null;
            var _loc_32:String = null;
            var _loc_33:IUITextField = null;
            var _loc_34:Object = null;
            var _loc_35:String = null;
            var _loc_36:Sprite = null;
            var _loc_37:Number = NaN;
            _marginTop = getStyle("marginTop");
            _marginBottom = getStyle("marginBottom");
            _marginLeft = getStyle("marginLeft");
            _marginRight = getStyle("marginRight");
            _switchable = getStyle("switchable");
            _switchType = getStyle("switchType");
            var _loc_1:* = getStyle("switchColor");
            var _loc_2:* = getStyle("markerLabelGap");
            var _loc_3:* = getStyle("verticalGap");
            var _loc_4:* = getStyle("horizontalGap");
            _loc_5 = getStyle("markerSize");
            var _loc_6:* = getStyle("markerBorderThickness");
            var _loc_7:* = getStyle("valueWidth");
            var _loc_8:* = getStyle("markerDisabledColor");
            _grid.horizonalGap = _loc_4;
            _grid.verticalGap = getStyle("verticalGap");
            var _loc_9:* = this.width - 2 * _loc_4 - _loc_5 - _loc_2 - _loc_7 - _marginLeft - _marginRight;
            if (_adjustWidth)
            {
                _loc_9 = _loc_9 + _loc_7;
            }
            var _loc_10:Number = 0;
            _valueFields = new Array();
            _titleFields = new Array();
            _switches = new Array();
            _entryContainers = new Array();
            var _loc_11:* = determineTextFormatFromStyles();
            _loc_11.leftMargin = _loc_2;
            if (isNaN(_initialTextColor))
            {
                _initialTextColor = this.getStyle("color");
            }
            _negativeValueColor = this.getStyle("negativeValueColor");
            _positiveValueColor = this.getStyle("positiveValueColor");
            var _loc_12:* = _dataProvider.length;
            var _loc_13:Number = 0;
            var _loc_14:* = _loc_12;
            var _loc_15:Number = 1;
            if (getStyle("reversedOrder"))
            {
                _loc_13 = _loc_12 - 1;
                _loc_14 = -1;
                _loc_15 = -1;
            }
            var _loc_16:* = _loc_13;
            while (_loc_16 != _loc_14)
            {
                
                _loc_17 = _dataProvider.getItemAt(_loc_16);
                _loc_18 = new ExtendedSprite();
                _entryContainers.push(_loc_18);
                _loc_18.index = _loc_17.index;
                _loc_19 = Utils.checkNull(_loc_17.markerType, getStyle("markerType") as String);
                _loc_20 = _loc_17.legendKeyColor;
                _loc_21 = _loc_17.legendAlpha;
                _loc_22 = getStyle("markerBorderColor") as Number;
                if (!_loc_22)
                {
                    _loc_22 = _loc_20;
                }
                _loc_11.color = _initialTextColor;
                if (_loc_17.hidden)
                {
                    if (_loc_8)
                    {
                        _loc_20 = _loc_8;
                        _loc_22 = _loc_20;
                    }
                }
                if (_loc_17 is AmGraph)
                {
                    _loc_29 = _loc_17.getStyle("lineThickness");
                    if (!isNaN(_loc_29))
                    {
                        if (_loc_19 != "line")
                        {
                        }
                    }
                    if (_loc_19 == "dashedLine")
                    {
                        _loc_6 = _loc_29;
                    }
                }
                _loc_23 = new Sprite();
                _loc_23.graphics.lineStyle(_loc_6, _loc_22, 1);
                _loc_23.graphics.beginFill(_loc_20, _loc_21);
                switch(_loc_19)
                {
                    case "square":
                    {
                        _loc_23.graphics.drawRect(0, 0, _loc_5, _loc_5);
                        break;
                    }
                    case "circle":
                    {
                        _loc_23.graphics.drawCircle(_loc_5 / 2, _loc_5 / 2, _loc_5 / 2);
                        break;
                    }
                    case "line":
                    {
                        _loc_24 = new Sprite();
                        _loc_24.graphics.lineStyle(0, 0, 0);
                        _loc_24.graphics.beginFill(0, 0);
                        _loc_24.graphics.drawRect(0, 0, _loc_5, _loc_5);
                        _loc_23.addChild(_loc_24);
                        _loc_23.graphics.moveTo(0, _loc_5 / 2);
                        _loc_23.graphics.lineTo(_loc_5, _loc_5 / 2);
                        break;
                    }
                    case "dashedLine":
                    {
                        _loc_24 = new Sprite();
                        _loc_24.graphics.lineStyle(0, 0, 0);
                        _loc_24.graphics.beginFill(0, 0);
                        _loc_24.graphics.drawRect(0, 0, _loc_5, _loc_5);
                        _loc_23.addChild(_loc_24);
                        _loc_23.graphics.moveTo(0, _loc_5 / 2);
                        _loc_23.graphics.lineTo(_loc_5 / 2 - 2, _loc_5 / 2);
                        _loc_23.graphics.moveTo(_loc_5 / 2 + 2, _loc_5 / 2);
                        _loc_23.graphics.lineTo(_loc_5, _loc_5 / 2);
                        break;
                    }
                    case "triangleUp":
                    {
                        _loc_23.graphics.moveTo(0, _loc_5);
                        _loc_23.graphics.lineTo(_loc_5 / 2, 0);
                        _loc_23.graphics.lineTo(_loc_5, _loc_5);
                        _loc_23.graphics.lineTo(0, _loc_5);
                        break;
                    }
                    case "triangleDown":
                    {
                        _loc_23.graphics.moveTo(0, 0);
                        _loc_23.graphics.lineTo(_loc_5 / 2, _loc_5);
                        _loc_23.graphics.lineTo(_loc_5, 0);
                        _loc_23.graphics.lineTo(0, 0);
                        break;
                    }
                    case "bubble":
                    {
                        _loc_30 = new Wedge(0, 360, _loc_20, _loc_5 / 2, _loc_5 / 2, 0, 1, 0, 0, 0, 0, "radial", [0, -100]);
                        _loc_30.x = _loc_5 / 2;
                        _loc_30.y = _loc_5 / 2;
                        _loc_23.addChild(_loc_30);
                        break;
                    }
                    case "none":
                    {
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_23.filters = _filters;
                _loc_18.addChild(_loc_23);
                _loc_23.addEventListener(MouseEvent.ROLL_OVER, handleMarkerEvent);
                _loc_23.addEventListener(MouseEvent.ROLL_OUT, handleMarkerEvent);
                _loc_23.addEventListener(MouseEvent.CLICK, handleMarkerEvent);
                _loc_25 = new Sprite();
                _loc_18.addChild(_loc_25);
                _loc_25.x = _loc_5;
                _loc_26 = 0;
                _loc_27 = 0;
                if (_labelText)
                {
                    _loc_31 = IUITextField(createInFontContext(UITextField));
                    _loc_31.height = 0;
                    _loc_11.align = TextFormatAlign.LEFT;
                    if (_useMarkerColorForLabels)
                    {
                        _loc_11.color = _loc_20;
                    }
                    else
                    {
                        _loc_11.color = _initialTextColor;
                    }
                    if (_loc_17.hidden)
                    {
                        _loc_11.color = getStyle("disabledColor");
                    }
                    if (_loc_17.showBalloon)
                    {
                    }
                    if (_textClickEnabled)
                    {
                        _loc_11.underline = true;
                    }
                    else
                    {
                        _loc_11.underline = false;
                    }
                    _loc_31.width = _loc_9;
                    _loc_31.multiline = true;
                    _loc_31.wordWrap = !_adjustWidth;
                    _loc_31.selectable = false;
                    _loc_31.defaultTextFormat = _loc_11;
                    _loc_31.setTextFormat(_loc_11);
                    _loc_31.antiAliasType = _loc_11.antiAliasType;
                    _loc_31.gridFitType = _loc_11.gridFitType;
                    _loc_31.sharpness = _loc_11.sharpness;
                    _loc_31.thickness = _loc_11.thickness;
                    if (systemManager)
                    {
                    }
                    _loc_31.embedFonts = systemManager.isFontFaceEmbedded(_loc_11);
                    _loc_32 = Utils.formatString(_labelText, _loc_17, _numberFormatter, _percentFormatter);
                    _loc_32 = cleanFromEmpty(_loc_32);
                    _loc_31.htmlText = _loc_32;
                    _loc_31.width = Math.min(_loc_31.textWidth + 5 + _loc_2, _loc_9);
                    _loc_31.height = _loc_31.textHeight + 4;
                    _loc_25.addChild(DisplayObject(_loc_31));
                    _titleFields[_loc_16] = _loc_31;
                    if (_loc_10 < _loc_31.width)
                    {
                        _loc_10 = _loc_31.width;
                    }
                    _loc_26 = _loc_31.width;
                    _loc_27 = _loc_31.textHeight;
                }
                _loc_28 = _valueText;
                if (_loc_17 is AmGraph)
                {
                    if (_loc_17.legendValueText)
                    {
                        _loc_28 = _loc_17.legendValueText;
                    }
                }
                if (valueText)
                {
                    _loc_11.underline = false;
                    _loc_33 = IUITextField(createInFontContext(UITextField));
                    _loc_33.height = 0;
                    _loc_11.align = getStyle("valueAlign");
                    _loc_33.width = _loc_7;
                    _loc_33.multiline = true;
                    _loc_33.selectable = false;
                    _loc_33.defaultTextFormat = _loc_11;
                    _loc_33.setTextFormat(_loc_11);
                    _loc_33.antiAliasType = _loc_11.antiAliasType;
                    _loc_33.gridFitType = _loc_11.gridFitType;
                    _loc_33.sharpness = _loc_11.sharpness;
                    _loc_33.thickness = _loc_11.thickness;
                    if (systemManager)
                    {
                    }
                    _loc_33.embedFonts = systemManager.isFontFaceEmbedded(_loc_11);
                    if (!_loc_17.hasOwnProperty("currentDataItem"))
                    {
                        _loc_35 = Utils.formatString(_loc_28, _loc_17, _numberFormatter, _percentFormatter, _positiveValueColor, _negativeValueColor, _usePositiveNegativeOnPercentsOnly, _chart.usePrefixes, _chart.prefixesOfBigNumbers, _chart.prefixesOfSmallNumbers);
                    }
                    if (!_loc_35)
                    {
                        _loc_35 = " ";
                    }
                    if (_valueFunction != null)
                    {
                        _loc_35 = _valueFunction(_loc_35);
                    }
                    _loc_33.htmlText = _loc_35;
                    _loc_33.height = _loc_33.textHeight + 4;
                    _loc_25.addChild(DisplayObject(_loc_33));
                    _loc_33.x = _loc_26;
                    _valueFields[_loc_16] = _loc_33;
                }
                if (_loc_17.hidden)
                {
                    if (_loc_33)
                    {
                        _loc_33.enabled = false;
                    }
                    if (_loc_31)
                    {
                        _loc_31.enabled = false;
                    }
                }
                if (_loc_27 > _loc_5)
                {
                    _loc_23.y = (_loc_27 - _loc_5) / 2 + 2;
                }
                else if (_loc_27)
                {
                    _loc_25.y = (_loc_5 - _loc_27) / 2 - 1;
                }
                if (_switchable)
                {
                    switch(_switchType)
                    {
                        case "x":
                        {
                            _loc_36 = _loc_18.addChild(new _switchX()) as Sprite;
                            if (!_loc_17.hidden)
                            {
                                _loc_36.visible = false;
                            }
                            break;
                        }
                        case "v":
                        {
                            _loc_36 = _loc_18.addChild(new _switchV()) as Sprite;
                            if (_loc_17.hidden)
                            {
                                _loc_36.visible = false;
                            }
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    _loc_36.x = _loc_5 / 2;
                    _loc_36.y = _loc_23.y + _loc_5 / 2;
                    Utils.setRGB(_loc_36, _loc_1);
                    _switches[_loc_16] = _loc_36;
                    _loc_36.mouseEnabled = false;
                    _loc_36.mouseChildren = false;
                }
                _loc_25.addEventListener(MouseEvent.ROLL_OVER, handleTextEvent);
                _loc_25.addEventListener(MouseEvent.ROLL_OUT, handleTextEvent);
                _loc_25.addEventListener(MouseEvent.MOUSE_UP, handleTextEvent);
                if (_loc_17.visibleInLegend)
                {
                    _grid.addChild(_loc_18);
                }
                _loc_16 = _loc_16 + _loc_15;
            }
            _loc_16 = 0;
            while (_loc_16 < _loc_12)
            {
                
                if (_valueFields[_loc_16])
                {
                    _loc_37 = 0;
                    if (_titleFields[_loc_16])
                    {
                        _loc_37 = _titleFields[_loc_16].width;
                    }
                    _valueFields[_loc_16].width = _valueFields[_loc_16].width + (_loc_10 - _loc_37);
                }
                _loc_16 = _loc_16 + 1;
            }
            _legendCreated = true;
            return;
        }// end function

        protected function handleMarkerEvent(event:MouseEvent) : void
        {
            var _loc_3:String = null;
            var _loc_4:LegendEvent = null;
            var _loc_2:* = event.currentTarget.parent.index;
            if (_loc_2 < _dataProvider.length)
            {
                if (event.type == MouseEvent.ROLL_OVER)
                {
                    if (_switchable)
                    {
                        _loc_3 = LegendEvent.ROLL_OVER_MARKER;
                    }
                    else
                    {
                        _loc_3 = LegendEvent.ROLL_OVER_ITEM;
                        rollOverItem(_loc_2);
                    }
                }
                if (event.type == MouseEvent.ROLL_OUT)
                {
                    if (_switchable)
                    {
                        _loc_3 = LegendEvent.ROLL_OUT_MARKER;
                    }
                    else
                    {
                        _loc_3 = LegendEvent.ROLL_OUT_ITEM;
                        rollOutItem(_loc_2);
                    }
                }
                if (event.type == MouseEvent.CLICK)
                {
                    if (_switchable)
                    {
                        if (_switches[_loc_2].visible == true)
                        {
                            if (_switchType == "v")
                            {
                                _loc_3 = LegendEvent.HIDE_ITEM;
                            }
                            else
                            {
                                _loc_3 = LegendEvent.SHOW_ITEM;
                            }
                        }
                        else if (_switchType == "v")
                        {
                            _loc_3 = LegendEvent.SHOW_ITEM;
                        }
                        else
                        {
                            _loc_3 = LegendEvent.HIDE_ITEM;
                        }
                    }
                    else if (_textClickEnabled)
                    {
                        _loc_3 = LegendEvent.CLICK_MARKER;
                    }
                }
                if (_loc_3)
                {
                    _loc_4 = new LegendEvent(_loc_3);
                    _loc_4.index = _loc_2;
                    _loc_4.item = _dataProvider.getItemAt(_loc_2);
                    dispatchEvent(_loc_4);
                }
            }
            return;
        }// end function

        protected function handleTextEvent(event:MouseEvent) : void
        {
            var _loc_3:Object = null;
            var _loc_4:String = null;
            var _loc_5:LegendEvent = null;
            var _loc_2:* = event.currentTarget.parent.index;
            if (_loc_2 < _dataProvider.length)
            {
                _loc_3 = _dataProvider.getItemAt(_loc_2);
                if (!_loc_3.hidden)
                {
                    if (event.type == MouseEvent.ROLL_OVER)
                    {
                        rollOverItem(_loc_2);
                        _loc_4 = LegendEvent.ROLL_OVER_ITEM;
                    }
                    if (event.type == MouseEvent.ROLL_OUT)
                    {
                        rollOutItem(_loc_2);
                        _loc_4 = LegendEvent.ROLL_OUT_ITEM;
                    }
                    if (_textClickEnabled)
                    {
                        if (event.type == MouseEvent.MOUSE_UP)
                        {
                            _loc_4 = LegendEvent.CLICK_LABEL;
                        }
                    }
                    if (_loc_4)
                    {
                        _loc_5 = new LegendEvent(_loc_4);
                        _loc_5.index = _loc_2;
                        _loc_5.item = _loc_3;
                        dispatchEvent(_loc_5);
                    }
                }
            }
            return;
        }// end function

        public function set labelText(param1:String) : void
        {
            _labelText = param1;
            return;
        }// end function

        override public function setActualSize(param1:Number, param2:Number) : void
        {
            super.setActualSize(param1, this.measuredHeight);
            return;
        }// end function

        override public function styleChanged(param1:String) : void
        {
            super.styleChanged(param1);
            if (param1)
            {
                commitProperties();
                return;
            }
            return;
        }// end function

        public function rollOutItem(param1:uint) : void
        {
            var _loc_2:TextFormat = null;
            if (_titleFields[param1])
            {
                if (_titleFields[param1].enabled)
                {
                    _loc_2 = _titleFields[param1].defaultTextFormat;
                    if (_useMarkerColorForLabels)
                    {
                        _loc_2.color = _dataProvider.getItemAt(param1).legendKeyColor;
                    }
                    else
                    {
                        _loc_2.color = this.getStyle("color");
                    }
                    _titleFields[param1].setTextFormat(_loc_2);
                }
            }
            return;
        }// end function

        protected function valuesChangedHandler(event:Event) : void
        {
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            var _loc_4:Object = null;
            var _loc_5:String = null;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_8:String = null;
            if (_valueFields)
            {
                _loc_2 = _valueFields.length;
                _loc_3 = 0;
                while (_loc_3 < _loc_2)
                {
                    
                    if (_loc_3 < _dataProvider.length)
                    {
                        _loc_4 = _dataProvider.getItemAt(_loc_3);
                        if (_loc_4.hasOwnProperty("currentDataItem"))
                        {
                            if (_loc_4.currentDataItem)
                            {
                                _loc_5 = _valueText;
                                if (_loc_4 is AmGraph)
                                {
                                    if (_loc_4.legendValueText)
                                    {
                                        _loc_5 = _loc_4.legendValueText;
                                    }
                                }
                                _loc_6 = _positiveValueColor;
                                _loc_7 = _negativeValueColor;
                                if (_loc_4.hidden)
                                {
                                    _loc_6 = NaN;
                                    _loc_7 = NaN;
                                }
                                _loc_8 = Utils.formatString(_loc_5, _loc_4.currentDataItem.values, _numberFormatter, _percentFormatter, _loc_6, _loc_7, _usePositiveNegativeOnPercentsOnly, _chart.usePrefixes, _chart.prefixesOfBigNumbers, _chart.prefixesOfSmallNumbers);
                                _loc_8 = Utils.formatString(_loc_8, _loc_4.currentDataItem, _numberFormatter, _percentFormatter, _loc_6, _loc_7, _usePositiveNegativeOnPercentsOnly, _chart.usePrefixes, _chart.prefixesOfBigNumbers, _chart.prefixesOfSmallNumbers);
                                _loc_8 = cleanFromEmpty(_loc_8);
                                if (_valueFunction != null)
                                {
                                    _loc_8 = _valueFunction(_loc_8);
                                }
                                _valueFields[_loc_3].htmlText = _loc_8;
                            }
                            else
                            {
                                _valueFields[_loc_3].htmlText = " ";
                            }
                        }
                    }
                    _loc_3 = _loc_3 + 1;
                }
            }
            return;
        }// end function

        public function get valueText() : String
        {
            return _valueText;
        }// end function

        public function set usePositiveNegativeOnPercentsOnly(param1:Boolean) : void
        {
            _usePositiveNegativeOnPercentsOnly = param1;
            return;
        }// end function

        protected function handleChartEvent(event:LegendEvent) : void
        {
            var _loc_2:* = event.type;
            var _loc_3:* = event.index;
            switch(_loc_2)
            {
                case LegendEvent.ROLL_OVER_ITEM:
                {
                    rollOverItem(_loc_3);
                    break;
                }
                case LegendEvent.ROLL_OUT_ITEM:
                {
                    rollOutItem(_loc_3);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get textClickEnabled() : Boolean
        {
            return _textClickEnabled;
        }// end function

        public function get valueFunction() : Function
        {
            return _valueFunction;
        }// end function

        override protected function measure() : void
        {
            var _loc_1:Number = NaN;
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            super.measure();
            this.measuredWidth = DEFAULT_MEASURED_WIDTH;
            if (_adjustWidth == true)
            {
                _loc_1 = 0;
                _loc_2 = 0;
                while (_loc_2 < _entryContainers.length)
                {
                    
                    _loc_3 = _entryContainers[_loc_2].width;
                    if (_loc_1 < _loc_3)
                    {
                        _loc_1 = _loc_3;
                    }
                    _loc_2 = _loc_2 + 1;
                }
                if (_loc_1 > 0)
                {
                    _loc_1 = _loc_1 + (this.getStyle("marginRight") + this.getStyle("marginLeft"));
                    this.measuredWidth = _loc_1;
                }
            }
            this.measuredHeight = _grid.height + this.getStyle("marginTop") + this.getStyle("marginBottom");
            return;
        }// end function

        public function get labelText() : String
        {
            return _labelText;
        }// end function

        public function get usePositiveNegativeOnPercentsOnly() : Boolean
        {
            return _usePositiveNegativeOnPercentsOnly;
        }// end function

        public function set dataProvider(param1:AmChart) : void
        {
            if (_chart)
            {
                _chart.removeEventListener("legendDataChanged", dataChangedHandler);
                _chart.removeEventListener("legendValuesChanged", valuesChangedHandler);
                _chart.removeEventListener("legendStylesChanged", dataChangedHandler);
            }
            _chart = param1;
            _chart.addEventListener("legendDataChanged", dataChangedHandler);
            _chart.addEventListener("legendValuesChanged", valuesChangedHandler);
            _chart.addEventListener("legendStylesChanged", dataChangedHandler);
            _chart.addEventListener(LegendEvent.ROLL_OVER_ITEM, handleChartEvent);
            _chart.addEventListener(LegendEvent.ROLL_OUT_ITEM, handleChartEvent);
            _chart.legend = this;
            dataChangedHandler();
            return;
        }// end function

        override protected function commitProperties() : void
        {
            super.commitProperties();
            _legendCreated = false;
            if (filters.length > 0)
            {
                _filters = filters.slice();
            }
            this.filters = [];
            invalidateDisplayList();
            return;
        }// end function

        public function set textClickEnabled(param1:Boolean) : void
        {
            _textClickEnabled = param1;
            return;
        }// end function

        public function set valueText(param1:String) : void
        {
            _valueText = param1;
            return;
        }// end function

        public function set adjustWidth(param1:Boolean) : void
        {
            _adjustWidth = param1;
            return;
        }// end function

        public function set valueFunction(param1:Function) : void
        {
            _valueFunction = param1;
            return;
        }// end function

        private static function initStyles() : Boolean
        {
            var styleDeclaration:* = StyleManager.getStyleDeclaration("AmLegend");
            if (!styleDeclaration)
            {
                styleDeclaration = new CSSStyleDeclaration();
                StyleManager.setStyleDeclaration("AmLegend", styleDeclaration, false);
            }
            styleDeclaration.defaultFactory = function () : void
            {
                this.backgroundAlpha = 0;
                this.backgroundColor = 16777215;
                this.borderAlpha = 0;
                this.borderColor = 14540253;
                this.markerLabelGap = 5;
                this.verticalGap = 10;
                this.align = "left";
                this.horizontalGap = 10;
                this.markerDisabledColor = 11187123;
                this.markerType = "square";
                this.markerSize = 16;
                this.markerBorderColor = NaN;
                this.markerBorderThickness = 0;
                this.maxColumns = NaN;
                this.marginTop = 10;
                this.marginBottom = 10;
                this.marginRight = 80;
                this.marginLeft = 80;
                this.valueWidth = 50;
                this.valueAlign = "right";
                this.switchable = true;
                this.switchType = "x";
                this.switchColor = 16777215;
                this.rollOverColor = 13369344;
                this.rollOverGraphAlpha = 1;
                this.reversedOrder = false;
                this.positiveValueColor = undefined;
                this.negativeValueColor = undefined;
                return;
            }// end function
            ;
            return true;
        }// end function

    }
}
